/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 - 2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.taglib.head.title;

/**
 * This class represents a title.
 */
public class Title
    implements Comparable<Title>
{
  /**
   * the content text of this title.
   */
  private final transient String text;

  /**
   * the priority of this title.
   */
  private final transient int priority;



  /**
   * constructor.
   * 
   * @param text
   *          the content text of the title
   * @param priority
   *          the priority of this title
   */
  public Title(final String text, final int priority)
  {
    this.text = text;
    this.priority = priority;
  }



  /**
   * comparaison method.
   * 
   * @param title
   *          the other title
   * @return the value <code>0</code> if the title has the same priority; a
   *         value less than <code>0</code> if this title has a lesser
   *         priority than the title argument; and a value greater than
   *         <code>0</code> if this title has a greater priority than the
   *         function argument.
   */
  public int compareTo(final Title title)
  {
    final int res = title.priority - this.priority;
    return res;
  }



  /**
   * Return true if the two titles have the same priority.
   * 
   * @param obj
   *          the other title
   * @return true if the two titles have the same priority.
   */
  @Override
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Title other = (Title) obj;
    if (priority != other.priority) {
      return false;
    }
    return true;
  }



  /**
   * Returns a hash code value for the object. This method is supported for the
   * benefit of hashtables such as those provided by {@link java.util.Hashtable}.
   * 
   * @return a hash code value for this object.
   * @see java.lang.Object#equals(java.lang.Object)
   * @see java.util.Hashtable
   */
  @Override
  public int hashCode()
  {
    return priority;
  }



  /**
   * getter for the text property.
   * 
   * @return the text
   */
  public String getText()
  {
    return text;
  }

}
